package steps;

import android.app.DialogFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.metodo_ahp.usuario.aplicacionmetodoahp.R;

import adapters.ListAdapterCriterios;
import dialog.DlgCompararAlternativas;
import gestores.GestorModeloAHP;
import libreria.WizardStep;

/**
 * Created by Usuario on 26/09/2014.
 */
public class step_4_comp_alternativas extends WizardStep implements AdapterView.OnItemLongClickListener{

    ListAdapterCriterios adapter;
    ListView lstCriterios;

    GestorModeloAHP gestorModelo;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        gestorModelo = (GestorModeloAHP) getActivity().getApplicationContext();
        gestorModelo.construirMatriz(false); //Construyo el hashmap con las matrices de alternativas.


    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);

        return inflater.inflate(R.layout.step_4_comparar_alternativas_exp_list, container, false);
    }

    public step_4_comp_alternativas() {

    }

    /**

     * Cuando la fragmente esté completamente creada.
     * @param savedInstanceState
     */
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        //Obtengo el listview
        lstCriterios = (ListView) this.getView().findViewById(R.id.lstCriterios);
        adapter = new ListAdapterCriterios(this.getActivity(), R.layout.step_4_lista_alternativas_header, gestorModelo.getListaCriterios());
        lstCriterios.setAdapter(adapter);

        lstCriterios.setOnItemLongClickListener(this);
    }
    /**
     * Callback method to be invoked when an item in this view has been
     * clicked and held.
     * <p/>
     * Implementers can call getItemAtPosition(position) if they need to access
     * the data associated with the selected item.
     *
     * @param parent   The AbsListView where the click happened
     * @param view     The view within the AbsListView that was clicked
     * @param position The position of the view in the list
     * @param id       The row id of the item that was clicked
     * @return true if the callback consumed the long click, false otherwise
     */
    @Override
    public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

        // Create and show the dialog.
        DialogFragment newFragment = DlgCompararAlternativas.newInstance(gestorModelo,position);
        newFragment.show(getActivity().getFragmentManager(),"tag");
        return false;
    }
}
